/**
 * Copyright 2009 Erick Armbrust 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 *   
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */

package tapioca.util;

public class DatastoreStats {

  private boolean hasGatheredStats = false;
  private int numGetRequests;
  private int numGetEntities;
  private int numPutRequests;
  private int numPutEntities;
  private int numDeleteRequests;
  private int numDeleteEntities;  
  private int numIdAllocations;
  
  public boolean hasGatheredStats() {
    return hasGatheredStats;
  }
  
  public int getNumGetRequests() {
    return numGetRequests;
  }

  public int getNumGetEntities() {
    return numGetEntities;
  }

  public int getNumPutRequests() {
    return numPutRequests;
  }

  public int getNumPutEntities() {
    return numPutEntities;
  }

  public int getNumDeleteRequests() {
    return numDeleteRequests;
  }

  public int getNumDeleteEntities() {
    return numDeleteEntities;
  }
  
  public int getNumIdAllocations() {
    return numIdAllocations;
  }

  public void addGetRequests(int numGetRequests) {
    hasGatheredStats = true;
    this.numGetRequests += numGetRequests;
  }
  
  public void addGetEntities(int numGetEntities) {
    hasGatheredStats = true;
    this.numGetEntities += numGetEntities;
  }
  
  public void addPutRequests(int numPutRequests) {
    hasGatheredStats = true;
    this.numPutRequests += numPutRequests;
  }

  public void addPutEntities(int numPutEntities) {
    hasGatheredStats = true;
    this.numPutEntities += numPutEntities;
  }  
  
  public void addDeleteRequests(int numDeleteRequests) {
    hasGatheredStats = true;
    this.numDeleteRequests += numDeleteRequests;
  }  
  
  public void addDeleteEntities(int numDeleteEntities) {
    hasGatheredStats = true;
    this.numDeleteEntities += numDeleteEntities;
  }  
  
  public void addIdAllocations(int numIdAllocations) {
    hasGatheredStats = true;
    this.numIdAllocations += numIdAllocations;
  }
  
  @Override
  public String toString() {
    return "Datastore Statistics: \n" +
        "  - Gets: " + numGetRequests + " requests for " + numGetEntities + " entities\n" +
        "  - Puts: " + numPutRequests + " requests for " + numPutEntities + " entities\n" +
        "  - Deletes: " + numDeleteRequests + " requests for " + numDeleteEntities + " entities\n" +
        "  - ID Allocations: " + numIdAllocations;
    
  }
  
}
